const { Service } = require("egg");

class CodeService extends Service {
    /**
     * 添加验证码
     * @param {*} mobile
     * @param {*} code
     * @param {*} create_time
     */
    async add(mobile, code, create_time) {
        let sql =
            "insert into code (mobile, code, create_time) values (?, ?, ?)";
        let params = [mobile, code, create_time];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }

    /**
     * 根据手机号，查找验证码
     * @param {*} mobile
     */
    async findByMobile(mobile) {
        let sql = "select * from code where mobile = ?";
        let params = [mobile];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }

    /**
     * 根据手机号，删除验证码
     * @param {*} mobile
     */
    async deleteByMobile(mobile) {
        let sql = "delete from code where mobile = ?";
        let params = [mobile];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
}

module.exports = CodeService;
